package com.cqyc.shop.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cqyc.shop.comm.Pager;
import com.cqyc.shop.comm.commException;
import com.cqyc.shop.domain.Shop;
import com.cqyc.shop.services.ShopServices;

@WebServlet(urlPatterns="/tenDollar.do")
public class tenDollarServlet extends HttpServlet{

	private static final long serialVersionUID = 7535942101034256667L;
	private Logger logger = LoggerFactory.getLogger(getClass());
	private ShopServices shopServices = new ShopServices();
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			Shop shop = new Shop();
				
			//水果类
			Pager pager_sgl = new Pager();
			pager_sgl.setPageSize(12);
			pager_sgl.setCurrentPage(1);
			shop.setShopname("水果");
			
			List<Shop> shops_sgl = shopServices.findPager(shop,pager_sgl);

			request.setAttribute("shops_sgl",shops_sgl);
			
			//粮油类
			Pager pager_lyl = new Pager();
			pager_lyl.setPageSize(12);
			pager_lyl.setCurrentPage(1);
			shop.setShopname("粮油");
			
			List<Shop> shops_lyl = shopServices.findPager(shop,pager_lyl);

			request.setAttribute("shops_lyl",shops_lyl);
			
			//休闲食品
			Pager pager_xxsp = new Pager();
			pager_xxsp.setPageSize(12);
			pager_xxsp.setCurrentPage(1);
			shop.setShopname("休闲");
			
			List<Shop> shops_xxsp = shopServices.findPager(shop,pager_xxsp);

			request.setAttribute("shops_xxsp",shops_xxsp);
			
			logger.debug("查询数据成功");
			request.getRequestDispatcher("/tenDollar.jsp").forward(request, response);
		} catch (Exception e) {
			throw new commException("list查找出现异常");
		}
	}

	
}
